package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.api.ReceivedCouponsApi;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.GrowthValueCouponList;
import com.czy.owner.net.http.HttpManager;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wangyang on 2017/5/18 0018.
 */

public class GrowthValueCouponAdapter extends RecyclerArrayAdapter<GrowthValueCouponList> {

    private Context context;
    private OnGetCouponsSuccess onGetCouponsSuccess;

    public OnGetCouponsSuccess getOnGetCouponsSuccess() {
        return onGetCouponsSuccess;
    }

    public void setOnGetCouponsSuccess(OnGetCouponsSuccess onGetCouponsSuccess) {
        this.onGetCouponsSuccess = onGetCouponsSuccess;
    }

    public GrowthValueCouponAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new GrowthValueCouponHolder(parent);
    }

    class GrowthValueCouponHolder extends BaseViewHolder<GrowthValueCouponList> {


        @BindView(R.id.img_coupon)
        ImageView imgCoupon;
        @BindView(R.id.tv_money_num)
        TextView tvMoneyNum;
        @BindView(R.id.tv_description)
        TextView tvDescription;
        @BindView(R.id.tv_click)
        TextView tvClick;

        public GrowthValueCouponHolder(ViewGroup parent) {
            super(parent, R.layout.item_growth_coupon_list);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(final GrowthValueCouponList data) {
            super.setData(data);
            tvMoneyNum.setText(data.getDenomination());
            tvDescription.setText(data.getNote());
            tvClick.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onGetCouponsSuccess != null)
                        onGetCouponsSuccess.onSuccess(data);

                }
            });
        }
    }

    public interface OnGetCouponsSuccess {
        void onSuccess(GrowthValueCouponList data);

    }


}